﻿using DataShow.codeModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace DataShow.codeDAL
{
    public class WorkProcess
    {
        #region 构造函数
        SqlHelper sqlhelper;
        public WorkProcess()
        {
            sqlhelper = new SqlHelper();
        } 
        #endregion

        #region 添加一条排班表记录
        /// <summary>
        /// 添加一条排班表记录
        /// </summary>
        /// <param name="realdate">日期</param>
        /// <param name="station">站点</param>
        /// <param name="clock">预报时效</param>
        /// <param name="span_kind">起报时间</param>
        /// <param name="sendpoint">发报时刻</param>
        /// <param name="forecastnumber">发报员id</param>
        /// <returns></returns>
        public bool AddSchedule(string realdate, string station, string clock, string span_kind, string sendpoint, string forecastnumber)
        {
            string sql = "insert into New_Schedule values (@realdate,@station,@clock,@spankink,@sendpoint,@forecastnumber)";
            SqlParameter[] param = new SqlParameter[] 
            { 
                new SqlParameter("@realdate",realdate), 
                new SqlParameter("@station",station), 
                new SqlParameter("@clock",clock), 
                new SqlParameter("@spankink",span_kind), 
                new SqlParameter("@sendpoint",sendpoint), 
                new SqlParameter("@forecastnumber",forecastnumber),
            };
            return sqlhelper.ExecuteNonQuery(sql, param) > 0;
        }
        #endregion

        #region 删除一条排班表记录
        /// <summary>
        /// 删除一条排班表记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteSchedule(int id)
        {
            string sql = "delete from New_Schedule where id=@id";
            SqlParameter[] param = new SqlParameter[] { new SqlParameter("@id",id) };
            return sqlhelper.ExecuteNonQuery(sql, param) > 0;
        }
        #endregion

        #region 分页搜索排班表
        /// <summary>
        /// 分页搜索排班表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">记录数</param>
        /// <returns></returns>
        public DataTable Search(int pageIndex, int pageSize)
        {
            return new Common().Search("New_Schedule", pageSize, pageIndex, "", "*");
        } 
        #endregion

    }
}